/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  MaintenanceRepairListActivity.java   
 * @Package com.jiyi.activity.new_maintenance.repair   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-10-27 上午11:09:30   
 * @version V1.0     
 */  
package com.jiyi.activity.new_maintenance.repair;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shizhefei.view.indicator.FragmentListPageAdapter;
import com.shizhefei.view.indicator.IndicatorViewPager;
import com.shizhefei.view.indicator.IndicatorViewPager.IndicatorFragmentPagerAdapter;
import com.shizhefei.view.indicator.ScrollIndicatorView;
import com.shizhefei.view.indicator.slidebar.ColorBar;
import com.shizhefei.view.indicator.transition.OnTransitionTextListener;
import com.swift.base.ActivityBase;
import com.swift.maintenance.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**   
 * @ClassName:  MaintenanceRepairListActivity   
 * @Description:TODO(维保报修列表)   
 * @author: HYM  
 * @date:   2017-10-27 上午11:09:30   
 *      
 */
public class MaintenanceRepairListActivity extends ActivityBase{


	/* 头部 */
	@BindView(R.id.tvBack)
	TextView tvBack;
	@BindView(R.id.tvTitle)
	TextView tvTitle;
	@BindView(R.id.tvSearch)
	TextView tvSearch;
	
	@BindView(R.id.moretab_indicator)
	ScrollIndicatorView indicator;
	@BindView(R.id.moretab_viewPager)
	ViewPager mViewPage;
	IndicatorViewPager indicatorViewPager;

	private LayoutInflater inflate;
	private String[] names = { "待申报", "待审核", "已否决", "待维修", "已完成" };
	private int size = 5;

	Dialog dialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_maintenance_mytask);
		ButterKnife.bind(this);
		init();
	}
	
	@Override
	protected void onDestroy() {
		hideDialog(dialog);
		super.onDestroy();
	}

	private void init() {
		inflate = LayoutInflater.from(this);
		setTop();
		initIndicator();
	}

	

	private void setTop() {
		tvTitle.setText("报修任务");
		tvSearch.setVisibility(View.GONE);
	}

	private void initIndicator() {
		indicator.setScrollBar(new ColorBar(this, Color.parseColor("#16B0F4"),
				5));

		// 设置滚动监听
		int selectColorId = R.color.tab_top_on;
		int unSelectColorId = R.color.tab_top;
		int selectSizeId = R.dimen.tab_text_select;
		int unSelectSizeId = R.dimen.tab_text_noselect;

		indicator.setOnTransitionListener(new OnTransitionTextListener()
				.setValueFromRes(this, selectColorId, unSelectColorId,
						selectSizeId, unSelectSizeId));

		indicatorViewPager = new IndicatorViewPager(indicator, mViewPage);
		indicatorViewPager
				.setAdapter(new MyAdapter(getSupportFragmentManager()));
		indicatorViewPager.setPageOffscreenLimit(1);
	}

	private class MyAdapter extends IndicatorFragmentPagerAdapter {

		public MyAdapter(FragmentManager fragmentManager) {
			super(fragmentManager);
		}

		@Override
		public int getCount() {
			return size;
		}

		@Override
		public View getViewForTab(int position, View convertView,
				ViewGroup container) {
			if (convertView == null) {
				convertView = inflate.inflate(R.layout.tab_top, container,
						false);
			}
			TextView textView = (TextView) convertView;
			textView.setText(names[position % names.length]);
			textView.setPadding(20, 0, 20, 0);
			textView.setTextSize(15);
			return convertView;
		}

		@Override
		public Fragment getFragmentForPage(int position) {
			Fragment curFragment = null;
			Bundle bundle = null;
			switch (position) {
			case 0:
				curFragment = new MaintenanceRepairListFragment();
				bundle = new Bundle();
				bundle.putInt("type", 0);
				curFragment.setArguments(bundle);
				break;
			case 1:
				curFragment = new MaintenanceRepairListFragment();
				bundle = new Bundle();
				bundle.putInt("type", 1);
				curFragment.setArguments(bundle);
				break;
			case 2:
				curFragment = new MaintenanceRepairListFragment();
				bundle = new Bundle();
				bundle.putInt("type", 2);
				curFragment.setArguments(bundle);
				break;
			case 3:
				curFragment = new MaintenanceRepairListFragment();
				bundle = new Bundle();
				bundle.putInt("type", 3);
				curFragment.setArguments(bundle);
				break;
			case 4:
				curFragment = new MaintenanceRepairListFragment();
				bundle = new Bundle();
				bundle.putInt("type", 4);
				curFragment.setArguments(bundle);
				break;
			default:
				break;
			}

			return curFragment;
		}

		@Override
		public int getItemPosition(Object object) {
			return FragmentListPageAdapter.POSITION_NONE;
		}

	};

	@OnClick({ R.id.tvBack })
	public void onClick(View view) {
		Intent intent = null;
		switch (view.getId()) {
		case R.id.tvBack:
			finish();
			break;
		default:
			break;
		}
	}
}
